package com.infodms.dms.dao.sales.storageManage;

import java.sql.ResultSet;
import java.util.Map;

import org.apache.log4j.Logger;

import com.infodms.dms.common.Constant;
import com.infodms.dms.dao.common.BaseDao;
import com.infoservice.po3.bean.PO;
import com.infoservice.po3.bean.PageResult;

public class AddressAddQueryDAO  extends BaseDao{

	public static Logger logger = Logger.getLogger(AddressAddQueryDAO.class);
	private static final AddressAddQueryDAO dao = new AddressAddQueryDAO ();
	public static final AddressAddQueryDAO getInstance() {
		return dao;
	}
	
	
	public static PageResult <Map<String,Object>> getChangeList(String areaId, String status,String dealerId,String address, int pageSize,int curPage){
		StringBuffer sql = new StringBuffer("");
		sql.append("SELECT A.ID,\n");
		sql.append("       A.ADD_CODE,\n");  
		sql.append("       A.ADDRESS,\n");  
		sql.append("       TCU1.NAME LOW_AUDIT,\n");  
		sql.append("       TCU2.NAME FACTORY_AUDIT,\n");  
		sql.append("       A.LINK_MAN,\n");  
		sql.append("       A.TEL,\n");  
		sql.append("       A.REMARK,\n");  
		sql.append("       A.RECEIVE_ORG,\n");  
		sql.append("       A.STATUS\n");
		sql.append("  FROM TM_VS_ADDRESS A, TM_DEALER_BUSINESS_AREA TMDBA, TC_USER TCU1, TC_USER TCU2\n");  
		sql.append(" WHERE 1=1\n");  
		sql.append("   AND A.DEALER_ID = TMDBA.DEALER_ID\n");
		sql.append("   AND A.LOW_AUDIT = TCU1.USER_ID(+)\n");
		sql.append("   AND A.FACTORY_AUDIT = TCU2.USER_ID(+)\n");
		sql.append("   AND A.DEALER_ID IN ("+dealerId+")\n");  
		sql.append("   AND A.STATUS IN ("+Constant.DEALER_ADDRESS_CHANGE_STATUS_02+","+Constant.DEALER_ADDRESS_CHANGE_STATUS_03+","+Constant.STATUS_ENABLE+","+Constant.DEALER_ADDRESS_CHANGE_STATUS_FIRST_CHK+","+Constant.STATUS_DISABLE+")\n");
		if (null != address && !"".equals(address)) {
			sql.append("   AND A.ADDRESS LIKE '%"+address.trim()+"%'\n");
		}
		if (null != status && !"".equals(status)) {
			sql.append("   AND A.STATUS = "+status+"\n");
		}
		if (null != areaId && !"".equals(areaId)) {
			sql.append("   AND TMDBA.AREA_ID = " + areaId + "\n");
		}
		sql.append(" ORDER BY A.ID DESC\n");
		return dao.pageQuery(sql.toString(), null,dao.getFunName(),pageSize ,curPage );
	}
	@Override
	protected PO wrapperPO(ResultSet rs, int idx) {
		// TODO Auto-generated method stub
		return null;
	}

}
